package GUitest;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class JOptionPaneDemo2 extends JFrame {
    public static void main(String[] args) {
//        new JOptionPaneDemo2();
//        Frame frame = new Frame("这里在测试Panel");
//        //2.创建Panel容器对象
//        Panel panel = new Panel();
//
//        //3.往Panel容器中添加组件
//        panel.add(new TextField("这是一个测试文本"));
//        panel.add(new Button("这是一个测试按钮"));
//
//        //4.把Panel添加到Frame中
//        frame.add(panel);
//
//        //5.设置Frame的位置和大小
//        frame.setBounds(30,30,500,300);
//
//        //6.设置Frame可见
//        frame.setVisible(true);

//        Frame frame = new Frame("test");
//
//        ScrollPane scrollPane = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
//
//        scrollPane.add(new TextField("test Text"));
//        scrollPane.add(new Button("Button"));
//
//        frame.add(scrollPane);
//
//        frame.setBounds(600, 600, 600 ,600);
//
//        frame.setVisible(true);


    }

    public JOptionPaneDemo2(){
        JButton b1 = new JButton("消息对话框");
        JButton b2 = new JButton("确认对话框");
        JButton b3 = new JButton("选项对话框");

        b1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showConfirmDialog(b1, "确认信息", "信息", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
            }
        });

        b2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showConfirmDialog(b2, "确认信息", "信息", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE);
            }
        });

        b3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showConfirmDialog(b3, "确认信息", "信息", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
            }
        });

        this.setLayout(new FlowLayout());
        this.add(b1);
        this.add(b2);
        this.add(b3);
        this.setSize(400, 400);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
